package fr.auzaiphe.commun;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * Cette classe permet l'affichage de notre indice
 * @author Raphael
 *
 */

public class FenetreVisu extends JDialog
{
	private JTextField nom, contenu;
	private JLabel nomLabel, textLabel;

	private FenetreVisuInfo info;



	public FenetreVisu(JFrame parent, String title, FenetreVisuInfo info)
	{
		//On appelle le construteur de JDialog correspondant
		super( parent, title, false );
		this.setSize(550, 270);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.info = info;
		this.initComponent();
	}

	public FenetreVisuInfo showDialog()
	{
		this.setVisible(true);
		return this.info;
	}

	private void initComponent()
	{
		//Nom de l'element
		JPanel panNom = new JPanel();
		panNom.setPreferredSize(new Dimension(220, 60));
		panNom.setBorder(BorderFactory.createTitledBorder("Titre"));
		this.nomLabel = new JLabel(this.info.getNom());
		panNom.add(this.nomLabel);


		//Contenu de l'element
		JPanel panText = new JPanel();
		panText.setPreferredSize(new Dimension(300, 150));
		panText.setBorder(BorderFactory.createTitledBorder("Information"));
		//Ajout du contenu
		this.textLabel = new JLabel(this.info.getText());
		//JTextArea zoneText = new JTextArea();
		//JScrollPane ScrollzoneText= new JScrollPane( zoneText );
		//panText.add(ScrollzoneText, BorderLayout.CENTER);
		panText.add(this.textLabel);


		JPanel control = new JPanel();
		JButton okBouton = new JButton("OK");

		okBouton.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent arg0) {
				FenetreVisu.this.dispose();
			}

		});
		control.add(okBouton);

		this.getContentPane().add(panNom, BorderLayout.NORTH);
		this.getContentPane().add(panText, BorderLayout.CENTER);
		this.getContentPane().add(control, BorderLayout.SOUTH);
	}
}


